package com.oa.srms.apps.business.dormitory.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.oa.srms.apps.business.dormitory.IBedInfoService;
import com.oa.srms.apps.constants.IDEDStates;
import com.oa.srms.apps.dao.dormitory.IBedInfoDao;
import com.oa.srms.apps.entity.dormitory.BedInfoValue;

public class BedInfoServiceImpl implements IBedInfoService {

	@Autowired
	private IBedInfoDao bedInfoDao;
	@Autowired
	private BedInfoValue bedInfoValue;
	
	@Override
	public Integer addBedInfo(String building, String roomNo,
			Integer bedNo, Integer grade, Integer classNo, String gender) throws Exception {
		bedInfoValue.setBuilding(building);
		bedInfoValue.setRoomNo(roomNo);
		bedInfoValue.setBedNo(bedNo);
		bedInfoValue.setGrade(grade);
		bedInfoValue.setClassNo(classNo);
		bedInfoValue.setGender(gender);
		bedInfoValue.setStates(IDEDStates.ENABLE);
		return bedInfoDao.addBedInfo(bedInfoValue);
	}

	@Override
	public void modifyBedInfo(Integer id, String building, String roomNo,
			Integer bedNo, Integer grade, Integer classNo, String gender) throws Exception {
		bedInfoValue = this.queryById(id);
		if(bedInfoValue!=null){
			bedInfoValue.setBuilding(building);
			bedInfoValue.setRoomNo(roomNo);
			bedInfoValue.setBedNo(bedNo);
			bedInfoValue.setGrade(grade);
			bedInfoValue.setClassNo(classNo);
			bedInfoValue.setGender(gender);
		    bedInfoDao.editBedInfo(bedInfoValue);
		}

	}

	@Override
	public void deleteBedInfo(Integer id) throws Exception {
		bedInfoValue = bedInfoDao.queryById(id);
		
		bedInfoValue.setStates(IDEDStates.DELETE);
		
		bedInfoDao.editBedInfo(bedInfoValue);
	}

	@Override
	public BedInfoValue queryById(Integer id) throws Exception {
		return bedInfoDao.queryById(id);
	}

	@Override
	public List<BedInfoValue> queryBedInfo(String building, String roomNo,
			Integer grade, Integer classNo, Integer states, Integer rows,
			Integer pageNo) throws Exception {
		return bedInfoDao.queryBedInfo(building, roomNo, grade, classNo, states, rows, pageNo);
	}

	@Override
	public Integer getTotalPageNumber(String building, String roomNo,
			Integer grade, Integer classNo, Integer states, Integer rows) {
		return bedInfoDao.getTotalPageNumber(building, roomNo, grade, classNo, states, rows);
	}

	@Override
	public Integer getTotalNumber() {
		return bedInfoDao.getTotalNumber();
	}

	@Override
	public List<BedInfoValue> queryBedInfo(Integer grade, Integer classNo,
			String gender, Integer states) {
		return bedInfoDao.queryBedInfo(grade, classNo, gender, states);

	}

	@Override
	public void toEnable(Integer id) throws Exception {
		bedInfoValue = bedInfoDao.queryById(id);
		
		bedInfoValue.setStates(IDEDStates.ENABLE);
		
		bedInfoDao.editBedInfo(bedInfoValue);
		
	}

	@Override
	public void toDisable(Integer id) throws Exception {
		bedInfoValue = bedInfoDao.queryById(id);
		bedInfoValue.setStates(IDEDStates.DISABLE);
		bedInfoDao.editBedInfo(bedInfoValue);
		
	}


}
